package com.mycode.controller;

import com.mycode.domain.Payment;
import com.mycode.domain.ResponseResult;
import com.mycode.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Zengsh123 on 2020/3/9.
 */
@RestController
public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    @Value("${server.port}")
    private String server_port;

    @PostMapping("/payment/insert")
    public ResponseResult<Integer> insert(Payment payment){
        int result = paymentService.insert(payment);
        if (result > 0){
            return new ResponseResult<Integer>(200, "插入数据成功, port: " + server_port, result);
        }else {
            return new ResponseResult<Integer>(500, "插入数据失败, port: " + server_port, result);
        }
    }

    @GetMapping("/payment/get/{id}")
    public ResponseResult<Payment> get(@PathVariable("id") Long id){
        Payment result = paymentService.getPaymentById(id);
        if (result != null){
            return new ResponseResult<Payment>(200, "查询数据成功, port: " + server_port, result);
        }else {
            return new ResponseResult<Payment>(500, "无数据, port: " + server_port, null);
        }
    }
}
